home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1482.dms / var1482.adf / Scripts / arraydemo.mc next >
Text File  |  1994-07-07  |  3KB  |  137 lines

  1. /**********************
  2. *
  3. *    a demo of using arrays for animation.
  4. *
  5. *    this is a simple bouncing ball.  note that this could have
  6. *    been done easier, but that wouldn't show how the array can be used
  7. *
  8. *    the anim has 20 frames.
  9. *
  10. **********************/
  11.  
  12.  
  13. /*
  14. *    change these at will
  15. */
  16.  
  17. real ball_radius = 1.0        ; the radius of the ball
  18. real bounce_height = 5.0    ; the distance the ball travels in the bounce
  19. real ground_height = 0.0    ; the Y value of the ground
  20.  
  21. /*
  22. *    don't change these
  23. */
  24.  
  25. int numframes = 20                ; the number of frames in the anim
  26. real bounce_min = ground_height+ball_radius    ; add in ball_radius 'cause the loc
  27.                         ; of the sphere is the center of
  28.                         ; the ball, not the bottom
  29. real bounce_max = bounce_min+bounce_height    ; the height of the ball at its apex
  30.  
  31. /*****
  32. *
  33. *    the distance the ball has fallen is computed by
  34. *
  35. *        x = 0.5*a*t*t
  36. *
  37. *    where x is the distance fallen, t is the number of frames since
  38. *    the ball was dropped, and a is the acceleration.  since the ball
  39. *    falls bounce_height in numframes/2, we can solve for a...
  40. *
  41. */
  42.  
  43. real accel = bounce_height/(0.5*(numframes/2)*(numframes/2))
  44.  
  45. /*
  46. *    plug the values into the equation.  the ball falls 10 frame,
  47. *    then rises for ten.  bounce_y[0] is the value for the 1st frame, etc.
  48. */
  49.  
  50. array bounce_y = {
  51.     bounce_max-0.5*accel*0*0,
  52.     bounce_max-0.5*accel*1*1,
  53.     bounce_max-0.5*accel*2*2,
  54.     bounce_max-0.5*accel*3*3,
  55.     bounce_max-0.5*accel*4*4,
  56.     bounce_max-0.5*accel*5*5,
  57.     bounce_max-0.5*accel*6*6,
  58.     bounce_max-0.5*accel*7*7,
  59.     bounce_max-0.5*accel*8*8,
  60.     bounce_max-0.5*accel*9*9,
  61.     bounce_max-0.5*accel*10*10,
  62.     bounce_max-0.5*accel*9*9,
  63.     bounce_max-0.5*accel*8*8,
  64.     bounce_max-0.5*accel*7*7,
  65.     bounce_max-0.5*accel*6*6,
  66.     bounce_max-0.5*accel*5*5,
  67.     bounce_max-0.5*accel*4*4,
  68.     bounce_max-0.5*accel*3*3,
  69.     bounce_max-0.5*accel*2*2,
  70.     bounce_max-0.5*accel*1*1
  71. }
  72.  
  73. color yellow {
  74.     diff    <1, 1, 0>
  75. }
  76.  
  77. sphere {
  78.     loc    <0, bounce_y[FRAME], 0>
  79.     radius    ball_radius
  80.     patt    yellow
  81. }
  82.  
  83. /**
  84. *
  85. *    this all just sets up the frame
  86. *
  87. **/
  88.  
  89. camera {
  90.     loc    <15, 3, 2>
  91.     target    <0, bounce_max/2, 0>
  92. ;    target    <0, bounce_y[FRAME], 0>    ; for fun, uncomment this and build the
  93.                     ; anim.  the camera tracks the ball!!
  94.                     ; the anim file will be huge, though...
  95. }
  96.  
  97. lamp {
  98.     loc    <9, 15, 4>
  99. }
  100.  
  101. color red {
  102.     diff    <1, 0, 0>
  103. }
  104.  
  105. color mirror {
  106.     diff    <.1, .1, .1>
  107. ;    refl    <.5, .5, .5>
  108. }
  109.  
  110. check red_mir {
  111.     patt1    red
  112.     patt2    mirror
  113.     xsize    1
  114.     ysize    1
  115.     zsize    1
  116. }
  117.  
  118. plane {
  119.     loc    <0, ground_height, 0>
  120.     v1    <1, 0, 0>
  121.     v2    <0, 0, 1>
  122.     patt    red_mir
  123. }
  124.  
  125. color off_white {
  126.     diff    <.85, .8, 1>
  127.     srefl    0
  128. }
  129.  
  130. plane {
  131.     loc    <-5, 0, 0>
  132.     v1    <0, 1, 0>
  133.     v2    <0, 0, 1>
  134.     patt    off_white
  135. }
  136.  
  137.